﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class SearchResult : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            execute();
        }
    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        execute();
    }
    private void execute()
    {
        string keywords = Request.QueryString["keywords"];
        string classname = Request.QueryString["classname"].ToString();
        lblClassname.Text = "您搜索的关键字是：【" + keywords + "】,这是在" + classname + "的搜索结果：";
        string sql;
        switch (classname)
        {
            case "全部文章":
                sql = "select * from News_Info where newsIsShow=1 and newsTitle like '%" + keywords + "%' order by newsTop desc, newsTime desc";
                if (DataAccess.GetCount(sql, null)!=0)
                {
                    newsResList.DataSource = DataAccess.GetDataTable(sql, null);
                    newsResList.DataBind();
                    DataPager1.Visible = true;
                }
                else
                {
                    DataPager1.Visible = false;
                }

                sql = "select notID,notTitle,notTop,notTime from Notice_Info where notIsShow=1 and notTitle like '%" + keywords + "%' order by notTop desc,notTime desc";
                if (DataAccess.GetCount(sql, null) != 0)
                {
                    notResList.DataSource = DataAccess.GetDataTable(sql, null);
                    notResList.DataBind();
                    DataPager2.Visible = true;
                }
                else
                {
                    DataPager2.Visible = false;
                }

                sql = "select depID,depTitle from Department_Info where depTitle like '%" + keywords + "%' order by depSort desc";
                if (DataAccess.GetCount(sql, null) != 0)
                {
                    introResList.DataSource = DataAccess.GetDataTable(sql, null);
                    introResList.DataBind();
                    DataPager3.Visible = true;
                }
                else
                {
                    DataPager3.Visible = false;
                }

                sql = "select * from Download_Info where dowIsShow=1 and dowTitle like '%" + keywords + "%'";
                if (DataAccess.GetCount(sql, null) != 0)
                {
                    downloadResList.DataSource = DataAccess.GetDataTable(sql, null);
                    downloadResList.DataBind();
                    DataPager4.Visible = true;
                }
                else
                {
                    DataPager4.Visible = false;
                }

                break;
            case "信息速递":
                DataPager1.Visible = true;
                sql = "select * from News_Info where newsIsShow=1 and newsTitle like '%" + keywords + "%'order by newsTop desc, newsTime desc";
                newsResList.DataSource = DataAccess.GetDataTable(sql, null);
                newsResList.DataBind();
                break;
            case "通知公告":
                DataPager2.Visible = true;
                sql = "select notID,notTitle,notTop,notTime from Notice_Info where notIsShow=1 and notTitle like '%" + keywords + "%' order by notTop desc,notTime desc";
                notResList.DataSource = DataAccess.GetDataTable(sql, null);
                notResList.DataBind();
                break;
            case "专业简介":
                DataPager3.Visible = true;
                sql = "select depID,depTitle from Department_Info where depTitle like '%" + keywords + "%' order by depSort desc";
                introResList.DataSource = DataAccess.GetDataTable(sql, null);
                introResList.DataBind();
                break;
            case "文件下载":
                DataPager4.Visible = true;
                sql = "select * from Download_Info where dowIsShow=1 and dowTitle like '%" + keywords + "%'";
                downloadResList.DataSource = DataAccess.GetDataTable(sql, null);
                downloadResList.DataBind();
                break;
            
        }
    }
}
//    public void dealWithIntro()
//    {
//        sql = "select depID,depTitle from Department_Info where depTitle like " + keywords + "order by depSort desc";
//        dir = "Intro.aspx?
           

//        DataTable dt = DataAccess.GetDataTable(sql, null);
//        title = dt.Rows[0]["depTitle"].ToString();
//        id = dt.Rows[0]["depID"].ToString();
//    }
//    public void dealWithNews()
//    {
        
//        sql = "select newsID,newsType,newsTime,newsTitle,newsTop,newsHot from News_Info where newsIsShow=1 and newsTitle like " + keywords + "order by newsTop desc newsTime desc";
//        dir = "News.aspx?ID=";
//        DataTable dt = DataAccess.GetDataTable(sql, null);
//        title = dt.Rows[0]["newsTitle"].ToString();
//        id = dt.Rows[0]["newsID"].ToString();
//    }
//    public void dealWithNotice()
//    {
        
//        sql = "select notID,notTitle,notTop,notTime from Notice_Info where notIsShow=1 and notTitle like" + keywords + "order by notTop desc,notTime desc";
//        dir = "Notice.aspx?Id=";
//        DataTable dt = DataAccess.GetDataTable(sql, null);
//        title = dt.Rows[0]["notTitle"].ToString();
//        id = dt.Rows[0]["notID"].ToString();
//    }
//}
//public class CommonUrl
//{
//    private string dir;
//    private string title;
//    private string id;

//}
